<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>{$meta_title}-狂雨小说CMS</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__ADMIN__/css/admin.css"></head>
  <link rel="stylesheet" href="__ADMIN__/css/font.css">
<body>
  <div class="layui-card layui-card-open">
    <div class="layui-card-body">
      <form class="layui-form" action="{:url()}">
        <div class="layui-form-item">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block w500">
            <input type="text" name="username" {notempty name="info.id"}disabled="disabled"{/notempty} class="layui-input" value="{$info.username|default=''}">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">email</label>
          <div class="layui-input-block w500">
            <input type="text" name="email" class="layui-input" value="{$info.email|default=''}">
          </div>
        </div>
        {notempty name="info.id"}
        <div class="layui-form-item">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-block w500">
            <div class="input-group">
              <input type="password" style="width:408px;" name="password" class="layui-input" value="">
              <button class="layui-btn" id="edit_password" type="button">修改密码</button>
            </div>
          </div>
        </div>
        {else/}
        <div class="layui-form-item">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-block w500">
              <input type="password" name="password" class="layui-input" value="">
          </div>
        </div>
        {/notempty}
        <div class="layui-form-item">
          <label class="layui-form-label">头像</label>
          <div class="layui-input-inline w400">
            <div class="input-group">
              <input type="text" style="width:308px;" name="headimgurl" value="{$info.headimgurl|default=''}" class="layui-input">
              <button class="layui-btn" id="upload" type="button">上传封面</button>
            </div>
          </div>
          <div class="layui-input-inline w100">
              <img src="{$info.headimgurl|default=''}" id="srcimgurl" style="height:50px;float: right;margin-right: 10px">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="正常" {eq name="info['status']|default=1" value="1"}checked{/eq}>
            <input type="radio" name="status" value="0" title="禁用" {eq name="info['status']|default=1" value="0"}checked{/eq}>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">积分</label>
          <div class="layui-input-inline">
            <input type="text" name="integral" class="layui-input" lay-verify="number" value="{$info.integral|default=0}">
          </div>
          <label class="layui-form-label">经验</label>
          <div class="layui-input-inline">
            <input type="text" name="exp" class="layui-input" lay-verify="number" value="{$info.exp|default=0}">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">介绍</label>
          <div class="layui-input-block w500">
            <textarea name="introduce" class="layui-textarea">{$info.introduce|default=''}</textarea>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <input name="id" type="hidden" value="{$info.id|default=""}" />
            <button class="layui-btn" lay-submit lay-filter="ajax" type="submit">提交</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript" src="__STATIC__/jquery/jquery.min.js"></script>
  <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js"></script>
  <script type="text/javascript" src="__ADMIN__/lib/cropper/croppers.js"></script>
  <script type="text/javascript" src="__ADMIN__/js/admin.js"></script>
  <script type="text/javascript">
    layui.config({
        base: '__ADMIN__/lib/cropper/' //layui自定义layui组件目录
    }).use(['form','croppers'], function () {
        var $ = layui.jquery
            ,form = layui.form
            ,croppers = layui.croppers
            ,layer= layui.layer;

        //创建一个头像上传组件
        croppers.render({
            elem: '#upload'
            ,saveW:150     //保存宽度
            ,saveH:150
            ,mark:1/1    //选取比例
            ,area:'900px'  //弹窗宽度
            ,path:'user/head'
            ,url: "{:url('upload/pic')}"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            ,done: function(url){ //上传完毕回调
                $('[name="headimgurl"]').val(url);
                $("#srcimgurl").attr('src',url);
            }
        });

        {notempty name="info.id"}
            $('#edit_password').click(function(event) {
                $.ajax({
                    method:"post",
                    url: "{:url('password')}", //用于文件上传的服务器端请求地址
                    data: {password:$('[name="password"]').val(),'id':{$info.id|default=""}},
                    success:function(result){
                        if(result.code == 1){
                            layer.msg(result.msg,{icon: 1});
                            $('[name="password"]').val('');
                        }else if(result.code == 0){
                            layer.msg(result.msg,{icon: 2});
                        }
                    }
                });
            });
        {/notempty}
    });
  </script>
</body>
</html>